package com.dgut.demo.service.impl;

import com.dgut.demo.bean.EmployeesMessage;
import com.dgut.demo.bean.LogsMessage;
import com.dgut.demo.bean.ParamsMessage;
import com.dgut.demo.controller.EmployeesController;
import com.dgut.demo.mapper.LogsMapper;
import com.dgut.demo.service.LogsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @Auther 虎
 * @Data 2021/2/19 20:09
 * @Version 1.0
 */
@Service
public class LogsServiceImpl implements LogsService {
    @Autowired
    private LogsMapper logsMapper;
    @Autowired
    private EmployeesController employeesController;

    @Override
    public List<LogsMessage> getAllLogsMessage() {
        return logsMapper.getAllLogsMessage();
    }

    @Override
    public int addOneLogsMessage(String actions, String id) {
        Date date = new Date(System.currentTimeMillis());
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        LogsMessage logsMessage = new LogsMessage();
        String times = dateFormat.format(date);
        EmployeesMessage employeesMessage = employeesController.getOneEmployeesMessage(id);
        String peoples = employeesMessage.getEname();
        logsMessage.setTimes(times);
        logsMessage.setActions(actions);
        logsMessage.setPeoples(peoples);
        return logsMapper.addOneLogsMessage(logsMessage);
    }

    @Override
    public List<LogsMessage> getLogsMessageByName(String peoples) {
        return logsMapper.getLogsMessageByName(peoples);
    }

    @Override
    public List<LogsMessage> getLogsMessageByTime(String begindate,String enddate) {
        ParamsMessage paramsMessage = new ParamsMessage();
        paramsMessage.setS1(begindate);
        paramsMessage.setS2(enddate);
        return logsMapper.getLogsMessageByTime(paramsMessage);
    }

    @Override
    public List<LogsMessage> getLogsMessageByNameAndTime(String peoples,String begindate,String enddate) {
        ParamsMessage paramsMessage = new ParamsMessage();
        paramsMessage.setS1(peoples);
        paramsMessage.setS2(begindate);
        paramsMessage.setS3(enddate);
        return logsMapper.getLogsMessageByNameAndTime(paramsMessage);
    }

}
